package cn.qidd.keep.product.model.product;

import cn.qidd.keep.domain.core.dict.ProductStatus;
import cn.qidd.keep.domain.document.QProduct;
import cn.qidd.keep.domain.model.BaseSearch;
import com.querydsl.core.BooleanBuilder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class ProductSearchParams extends BaseSearch {

    private String productName;
    private ProductStatus productStatus;
    private Boolean isDelete;

    @Override
    public BooleanBuilder generateSearchCondition() {
        BooleanBuilder builder = new BooleanBuilder();
        if (StringUtils.isNotBlank(productName)) {
            builder.and(QProduct.product.productName.containsIgnoreCase(productName));
        }
        if (productStatus != null) {
            builder.and(QProduct.product.productStatus.eq(productStatus));
        }
        if (isDelete != null) {
            builder.and(QProduct.product.isDelete.eq(isDelete));
        }
        return builder;
    }
}
